﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MC_AI_002
{
    class Track
    {
        private static int S_ID = 0;
        private int m_ID;

        private float[] m_Coord, m_Rot;
        private List<int> m_Neighbors; // a list of neighboring tracks' IDs

        public Track(Track dummyTrack)
        {
            
            this.m_ID = dummyTrack.m_ID;
            this.m_Coord = dummyTrack.m_Coord;
            this.m_Rot = dummyTrack.m_Rot;
            this.m_Neighbors = dummyTrack.m_Neighbors;

            //Console.Write("\t\tTrack[" + m_ID + "] created from DummyTrack[" + m_ID + "]\n");
        }
        public Track(float[] xyz, float[] abc)
        {
            m_ID = S_ID++;
            m_Coord = xyz;
            m_Rot = abc;
            m_Neighbors = new List<int>();

            //Console.Write("\t\tTrack[" + m_ID + "] Created\n");
        }
        public float[] getCoords()
        {
            return m_Coord;
        }
        public float[] getRot()
        {
            return m_Rot;
        }
        public int getID()
        {
            return m_ID;
        }

        // m_Neighbors is used to create track chains that are easy to follow
        public void addNeighbor(int n_ID)
        {
            m_Neighbors.Add(n_ID);
            //Console.WriteLine("Track[{0}] has added Track[{1}] to its list of neighbors.", m_ID, n_ID);
        }
        public bool removeNeighbor(int n_ID)
        {
            return m_Neighbors.Remove(n_ID); // returns true if the neighbor ID existed and is now removed; false if the ID cannot be found
        }
        public int getNumNeighbors()
        {
            return m_Neighbors.Count();
        }
        public int[] getNeighbors()
        {
            return m_Neighbors.ToArray();
        }
        public void printNeighbors()
        {
            foreach (int id in m_Neighbors)
            {
                Console.WriteLine("\t\tNeighbor: Track[{0}]", id);
            }
        }

        public bool isEqual(Track t_Track)
        {
            try
            {
                return (t_Track.getID() == this.m_ID) &&
                       (t_Track.getCoords() == this.m_Coord) &&
                       (t_Track.getRot() == this.m_Rot);
            }
            catch (NullReferenceException)
            {
                return false;
            }
        }
    }
}
